package 尊享面试.哈希;

public class a1165单行键盘 {
    static class Solution {
        public int calculateTime(String keyboard, String word) {
            int[] words = new int[26];
            for (int i = 0; i < keyboard.length(); i++) {
                words[keyboard.charAt(i) - 'a'] = i;
            }
            int ans = 0;
            int cur = 0;
            for (int i = 0; i < word.length(); i++) {
                int index = words[word.charAt(i) - 'a'];
                ans += Math.abs(index - cur);
                cur = index;
            }
            return ans;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String keyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode";
        System.out.println(solution.calculateTime(keyboard, word));
    }
}
